/**
 * Created By   : robertwilson
 * Date         : 5/4/13
 * Time         : 5:10 PM
 * File         :
 * Class        : Assessment
 */

var Assessment = (function() {

    var init = function () {
        console.log('Initialized...');
        bindEvents()
    };

    var bindEvents = function () {
        $('.assessment-form').find('input[type="checkbox"]').on('click', function() {
            var $this = $(this);
            var id = $this.parent().parent().data('id');
            var table = $this.parent().parent().data('table');
            var data = {
                changeStatus: 1,
                status: $this.val(),
                id: id,
                table: table
            };

           // console.log(data);

            $.ajax({
                url: '../pages/dashboard.php',
                type: 'post',
                dataType: 'JSON',
                data: data,
                success: function(callbackData) {
                    if (!!callbackData && typeof callbackData == 'object') {
                        $this.val(callbackData.status);
                        if (callbackData.status == 1) {
                            $this.parent().parent().addClass('completed');
                        } else {
                            $this.parent().parent().removeClass('completed');
                        }

                    }
                    //console.log( callbackData );
                },
                error: function(xhr, error) {

                }
            });
        });
    }

    return {
        initialize: function () {
            init();
        }
    };

})();


$(function() {
    Assessment.initialize();
})